Data Service Keys
This page last changed on Nov 28, 2008.
Oracle Data Service Integrator Documentation > Data Services Developer's Guide Data Service KeysThis topic describes what data service keys are and how they are used. OverviewYou are probably familiar with the concept of keys from relational databases, where a key is a set of one or more columns whose combined values are unique among all occurrences in a table. When you create a physical data service, Oracle Data Service Integrator computes keys by introspecting the physical data sources. A physical data service key can have one or more fields, which are elements taken from the service's return type. Tangibly, a key is defined as an XML schema in an XSD file. You can see the physical data service keys in your dataspace project in Workshop for WebLogic. They appear in schema files with names such as:
datasource_KEY.xsd Physical Data Service Keys in Workshop for WebLogicIn the generated XSD file, a key for a physical data service looks something like this. Key for the CUSTOMER Table<?xml version="1.0" encoding="UTF-8" ?> <xs:schema targetNamespace="ld:physical/CUSTOMER" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="CUSTOMER_KEY"> <xs:complexType> <xs:sequence> <xs:element name="CUSTOMER_ID" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> In this case, CUSTOMER_ID is the primary key in a relational table named CUSTOMER. In a logical data service, a key also uniquely defines a data record. However, the data in the record can originate from multiple data sources of different types and can have a structure unlike the underlying physical data sources. For a logical entity service, you must create the key. You can choose one of these options:
Parts of a KeySuppose a logical service has a nested return type where a parent element with single cardinality can have multiple child elements, say one CUSTOMER element with many CUSTOMER_ORDER child elements. A Nested Return Type with a One-to-Many Relationship<?xml version="1.0" encoding="UTF-8" ?> <xs:schema targetNamespace="ld:logical/CustomersAndOrders" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="CustomersAndOrders"> <xs:complexType> <xs:sequence> <xs:element name="CUSTOMER"> <xs:complexType> <xs:sequence> <xs:element name="CUSTOMER_ID" type="xs:string"/> <xs:element name="FIRST_NAME" type="xs:string"/> <xs:element name="LAST_NAME" type="xs:string"/> <xs:element name="SSN" type="xs:string" minOccurs="0"/> <xs:element name="CUSTOMER_ORDER" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="ORDER_ID" type="xs:string"/> <xs:element name="C_ID" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> This is the key that Oracle Data Service Integrator auto-generates from this return type, from the unique CUSTOMER_ID field: An Auto-Generated Simple Key<?xml version="1.0" encoding="UTF-8"?> <xs:schema targetNamespace="ld:logical/CustomerOrder" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="CustomersAndOrders_KEY"> <xs:complexType> <xs:sequence> <xs:element name="CUSTOMER_ID" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> If you choose to select the key fields, you need to use a unique field or fields with single cardinality. You can choose CUSTOMER_ID or SSN, or both. You cannot define the key on ORDER_ID or C_ID, because they belong to the CUSTOMER_ORDER element, which has multiple cardinality. If you choose SSN, the key schema file looks like this. A Manually Selected Key<?xml version="1.0" encoding="UTF-8"?> <xs:schema targetNamespace="ld:logical/CustomerOrder" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="CustomersAndOrders_KEY"> <xs:complexType> <xs:sequence> <xs:element name="SSN" maxOccurs="1" minOccurs="0" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> A data service key has distinct parts:
Composite KeysWith a logical service, a key can also be a composite key of multiple elements, as long as the elements have single cardinality in the return type. This is especially easy with a flat return type. A Flat, Non-Nested Return Type<?xml version="1.0" encoding="UTF-8" ?> <xs:schema targetNamespace="ld:logical/MyFlatOne" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="CUSTOMERORDER"> <xs:complexType> <xs:sequence> <xs:element name="CUSTOMER_ID" type="xs:string"/> <xs:element name="FIRST_NAME" type="xs:string"/> <xs:element name="LAST_NAME" type="xs:string"/> <xs:element name="EMAIL_ADDRESS" type="xs:string"/> <xs:element name="ORDER_ID" type="xs:string"/> <xs:element name="ORDER_DT" type="xs:date"/> <xs:element name="TOTAL_ORDER_AMT" type="xs:decimal"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> Oracle Data Service Integrator auto-generates a composite key using the key fields from the underlying physical data sources (in this example, CUSTOMER_ID and ORDER_ID). The composite key generated from this return type is shown below. An Auto-Generated Composite Key<?xml version="1.0" encoding="UTF-8"?> <xs:schema targetNamespace="ld:logical/MyFlatOne" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="MyFlatOne_KEY"> <xs:complexType> <xs:sequence> <xs:element name="CUSTOMER_ID" type="xs:string"/> <xs:element name="ORDER_ID" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> This key allows you to identify a unique combination of Customer and Order, that is, one order for one customer. See AlsoHow Tos |
![]() |
Document generated by Confluence on Jan 13, 2009 15:57 |